package com.huike.web.controller.review;


import com.huike.business.domain.TbBusiness;
import com.huike.common.constant.HttpStatus;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.utils.StringUtils;
import com.huike.review.pojo.Review;
import com.huike.review.service.ReviewService;
import com.huike.review.vo.MybatisReviewVO;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * 该Controller主要是为了复习三层架构以及Mybatis使用的，该部分接口已经放开权限，可以直接访问
 * 同学们在此处编写接口通过浏览器访问看是否能完成最简单的增删改查
 */
@RestController
@RequestMapping("/review")
public class MybatisReviewController extends BaseController {

    @Autowired
    private ReviewService reviewService;


    /**
     * =========================================================新增数据============================================
     */
    @PostMapping("/saveData")
    public AjaxResult add(@RequestBody Review review) {
        int a = reviewService.insertReview(review);
        if (a > 0) {
            return AjaxResult.success("成功");
        } else {
            return AjaxResult.error("败了");
        }
    }


    /**
     * =========================================================删除数据=============================================
     */
    @DeleteMapping("/remove/{id}")
    public AjaxResult delete(@PathVariable Long id) {
        Long a = reviewService.deleteReview(id);
        if (a > 0) {
            return AjaxResult.success("成功");
        } else {
            return AjaxResult.error("败了");
        }
    }

    @PostMapping("/update")
    public AjaxResult update(@RequestBody Review review) {
        int i = reviewService.updateReview(review);
        if (i > 0) {
            return AjaxResult.success("成功");
        } else {
            return AjaxResult.error("败了");
        }

    }

    @GetMapping("/{id}")
    public AjaxResult selectById(Long id){
        Review review = this.reviewService.selectReview(id);
        return AjaxResult.success("成功",review);
    }

@GetMapping("/getDataByPage")
    public TableDataInfo pool(Long page,Long pageSize, HttpServletRequest req){
        startPage();
        List<Review> list = reviewService.selectReviewByPage(page,pageSize);
        return getDataTable(list);
    }

}
















